package main;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.table.DefaultTableModel;

public abstract class AbstractNItableModel extends DefaultTableModel {
	File file;

	public AbstractNItableModel() {
		file = createDataFile();
		parseFile(file);
	}

	public abstract File createDataFile();

	/**
	 * 
	 * @param f
	 */
	private void parseFile(File f) {
		try {
			BufferedReader in = new BufferedReader(new FileReader(f));
			String aLine = in.readLine();
			String[] colName = aLine.split("\t");
			setColumnIdentifiers(colName);
			while ((aLine = in.readLine()) != null) {
				String[] rowData = aLine.split("\t");
				addRow(rowData);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 * @param location
	 * @param headValue
	 * @return done
	 */
	protected abstract Object getValue(String indexCol_headerName,
			Object cellValue, String headValue);

	@Override
	public boolean isCellEditable(int row, int column) {
		return false;
	}

}
